import React, {useRef} from 'react';
import { useNavigate } from 'react-router-dom';
import {store} from '../store/index'
import {addGoods} from '../store/slice/goods'

function AddGoods(props) {
    const goodsNameRef = useRef()
    const goodsPriceRef = useRef()
    const navigate = useNavigate()
    return (
        <form onSubmit={(e) => {
            e.preventDefault()
            store.dispatch(addGoods({
                goodsName: goodsNameRef.current.value.trim(),
                goodsPrice: goodsPriceRef.current.value.trim()/1
            }))
            navigate('./goodsList')
        }}>


            <p>商品名称：<input ref={goodsNameRef} type='text'></input></p>
            <p>商品价格：<input ref={goodsPriceRef} type='number'></input></p>
            <button>提交</button>
        </form>
    );
}

export default AddGoods;